/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.android.ui.page;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.GlideUtil;
import com.NewActionHelp;
import com.bumptech.glide.Glide;
import com.google.gson.reflect.TypeToken;
import com.shwread.android.qysw.activity.AtlasActivity;
import com.shwread.android.qysw.activity.AtlasSeeActivity;
import com.shwread.android.qysw.activity.BaseBusinessActivity;
import com.shwread.android.qysw.activity.CommentListActivity;
import com.shwread.android.qysw.activity.ImageTextActivity;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw.activity.NewBookDetailActivity;
import com.shwread.android.qysw.activity.VideoDetailActivity;
import com.shwread.android.qysw10000241.R;
import com.shwread.android.ui.customview.LinearListView;
import com.shwread.android.ui.dialog.GuideDialog;
import com.shwread.android.ui.dialog.NoNetDialog;
import com.shwread.android.ui.widget.BookCoverView;
import com.shwread.android.ui.widget.RegionModelView;
import com.shwread.android.ui.widget.refresh.PullToRefreshScrollView;
import com.shwread.android.ui.widget.refresh.PullToRefreshUtil;
import com.shwread.android.ui.widget.refresh.base.PullToRefreshBase;
import com.shwread.http.base.ObjectHttpResponseHandler;
import com.shwread.httpsdk.http.callback.BaseAction;
import com.shwread.httpsdk.http.face.QryCommentPraiseNumAction;
import com.tgx.tina.android.ipc.framework.IUIPage;

import org.apache.http.Header;
import org.geometerplus.android.util.QyreaderPerferencesUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import base.tina.core.task.infc.ITaskResult;
import cn.bingoogolapple.bgabanner.BGABanner;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
import logic.bean.AudioAndVideo;
import logic.bean.BannerInfo;
import logic.bean.BookInfo;
import logic.bean.ImageCollection;
import logic.bean.MultiNews;
import logic.bean.NumberInfo;
import logic.bean.RegionContentItemBean;
import logic.bean.SingleBook;
import logic.bean.SingleNews;
import logic.constants.DefaultConsts;
import logic.util.DateUtil;
import logic.util.NetworkUtil;
import logic.util.Util;


public class NewEnterprisePage
        extends
        AbstractUIPage<MainActivity> implements BGABanner.Adapter<ImageView, BannerInfo>
        , BGABanner.Delegate<ImageView, BannerInfo>
        , LinearListView.OnItemClickListener, RegionModelView.OnModuleSelectedListener
        , View.OnClickListener {
    public static final int PAGESIZE = 5;
    public static final int CONTENT_ITEM_MAX_SIZE = 60;
    public static final int IMAGE_COUNT = 5;
    private final static int SINGLE_NEWS_TYPE = 1;
    private final static int MULTI_NEWS_TYPE = 2;
    private final static int AUDIO_NEWS_TYPE = 3;
    private final static int VIDEO_NEWS_TYPE = 4;
    private final static int IMAGE_SET_TYPE = 5;
    private final static int SINGLE_BOOK_TYPE = 6;
    private static final char REGION_SPLITOR = 8;
    public static boolean netAvilible = true;
    private static NewEnterprisePage instance;
    /**
     * 双击有效时间500毫秒
     */
    private final int defalultValue = 500;
    List<RegionContentItemBean> mContentItemList = new ArrayList<>(); //内容项列表
    View.OnClickListener multiIfoOnclickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Object objPositions = v.getTag();
            if (objPositions == null) return;
            String positions = (String) objPositions;
            int splitorPos = positions.indexOf(REGION_SPLITOR);
            int position1 = Integer.parseInt(positions.substring(0, splitorPos));
            int position2 = Integer.parseInt(positions.substring(splitorPos + 1));
            //todo 跳转到图文详情
            //gotoImageTextActivity(url, title);
            RegionContentItemBean contentItem = mContentItemList.get(position1);
            MultiNews multiNews = contentItem.getMutilNews();
            String contentType = multiNews.getNewsType(position2);
            if (contentType.equalsIgnoreCase("1")) { //单条资讯
                //todo 跳转到图文详情
                SingleNews singleNews = (SingleNews) multiNews.getNewsObject(position2);
                gotoImageTextActivity(singleNews.getHtmlUrl(), singleNews.getTitle(), singleNews.getModelContentDetailId() + "");
            } else if (contentType.equalsIgnoreCase("3")) {//音频
                // 跳转到图文详情
                AudioAndVideo audioNews = (AudioAndVideo) multiNews.getNewsObject(position2);
                gotoImageTextActivity(audioNews.getHtmlUrl(), audioNews.getTitle(), audioNews.getModelContentDetailId() + "");
            } else if (contentType.equalsIgnoreCase("4")) {//视频
                // 跳转到图文详情
                AudioAndVideo videoNews = (AudioAndVideo) multiNews.getNewsObject(position2);
                gotoImageTextActivity(videoNews.getHtmlUrl(), videoNews.getTitle(), videoNews.getModelContentDetailId() + "");
            } else if (contentType.equalsIgnoreCase("5")) { //图集
                //todo 跳转到查看图集图片
                ImageCollection imageSet = (ImageCollection) multiNews.getNewsObject(position2);
                int imgCounts = imageSet.getImageCollectionNum();
                Intent intent;
                if (imgCounts == 0) {
                    Toast.makeText(bActivity, "图集已下架", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (imgCounts <= IMAGE_COUNT) {
                    //直接进入看图片
                    intent = new Intent(bActivity, AtlasSeeActivity.class);
                    intent.putExtra(AtlasSeeActivity.FROM_TYPE, DefaultConsts.TAG_FROM_ENTERPRISE);
                    intent.putExtra(AtlasSeeActivity.IMAGE_COUNT, imgCounts);
                } else {//进入到瀑布流页面
                    intent = new Intent(bActivity, AtlasActivity.class);
                    intent.putExtra(AtlasActivity.ATLAS_NAME, imageSet.getTitle());
                }
                //设置图集的数据
                intent.putExtra(AtlasActivity.ATLAS_ID, imageSet.getImageCollectionId());
                bActivity.startActivity(intent);

            } else if (contentType.equalsIgnoreCase("6")) { //单本书籍
                //跳转到书籍详情
                SingleBook singleBook = (SingleBook) multiNews.getNewsObject(position2);
                BookInfo bookInfo = singleBook.getBookInfo();
                if (bookInfo == null) return;
                //#ifdef SHOW_OLDBOOKDETAIL
                //$ Intent intent = new Intent(bActivity, BookDetailActivity.class);
                //#else
                Intent intent = new Intent(bActivity, NewBookDetailActivity.class);
                //#endif
                bookInfo.setAuthor("");
                intent.putExtra("BookInfo", bookInfo);
                bActivity.startActivity(intent);
            }
        }
    };
    private LinearListView lv;
    private PullToRefreshScrollView refreshView;
    //轮播banner
    private List<BannerInfo> banners;
    private BGABanner bgaBanner;
    //模块
    private RegionModelView modelView;
    private long currentModelId = -1;
    private int mTotalItemCount = 0;
    private long moduleId;// 模块id
    private InfoAdapter mContentAdapter;
    private boolean hasMore = true;
    private int currentPage = 1;
    private ImageView switchImg;
    private View switchView;
    private AnimationDrawable switchDrawable;
    private RegionContentViewListener contentViewListener;
    private long currentPublishTime = 0;
    private int myRefreshFlag = 2; //1为 下拉刷新， 2为得到数据
    private String targetType;
    private String targetValue;
    private TextView tv_comments_count;
    View.OnClickListener commentsOnclickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Object objTarget = v.getTag();
            if (objTarget == null) return;
            String strTarget = (String) objTarget;
            int splitorPos = strTarget.indexOf(REGION_SPLITOR);
            targetType = strTarget.substring(0, splitorPos);
            targetValue = strTarget.substring(splitorPos + 1);
            RelativeLayout parent = (RelativeLayout) v.getParent();
            tv_comments_count = (TextView) parent.findViewById(R.id.tv_comments_count);
            Intent intent1 = new Intent();
            intent1.setClass(bActivity, CommentListActivity.class);
            intent1.putExtra(DefaultConsts.COMMENT_TARGET_TYPE, targetType);
            intent1.putExtra(DefaultConsts.COMMENT_TARGET_VALUE, targetValue);
            bActivity.startActivityForResult(intent1, BaseBusinessActivity.COMMENTS_REQUEST_CODE);
        }
    };
    private boolean isLastSuccess = false;
    private View loadingView;
    private ImageView loadingImg;
    private AnimationDrawable animationDrawable;
    private int titleHight = 0;
    private int regionHight = 0;
    private int bannerHight = 0;
    private int screenHeight = 0;
    private View commonTitle = null;
    private RelativeLayout empty;
    private TextView                                 tvTitle;
    private ImageView 									 ivPersion;
    private List<String> list = new ArrayList<>();
    private GuideDialog dialog;
    private boolean showHelp;
    private QyreaderPerferencesUtil util;
    private int clickCount;
    private long preClickTime;

    private NewEnterprisePage(MainActivity t) {
        super(t);
    }

    public static NewEnterprisePage getInstance(MainActivity t) {
        if (instance == null) {
            instance = new NewEnterprisePage(t);
        } else {
            instance.setActivity(t);
        }
        return instance;
    }

    public static void destroy() {
        if (instance != null) {
            instance.dispose();
            instance = null;
        }
    }

    @Override
    public <E extends Activity> View createView(E arg0, int arg1) {
        if (null != curMyView) return curMyView;
        curMyView = bActivity.getLayoutInflater().inflate(R.layout.enterprise_page, null);
        initView();
        initData();
        initGuide();
        return curMyView;
    }

    void initData() {
        lv = (LinearListView) curMyView.findViewById(R.id.lv);
        lv.setOnItemClickListener(this);
        refreshView = (PullToRefreshScrollView) curMyView.findViewById(R.id.refreshView);
        PullToRefreshUtil.initLabel(context, refreshView);
        refreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ScrollView>() {
            @Override
            public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
                if (refreshView.isHeaderShown()) { //下拉刷新
                    modelView.setCanSwitchModule(false);
                    refresh();
                } else if (refreshView.isFooterShown()) { //上拉加载
                    loadMore();
                }
            }
        });
        loadingView = curMyView.findViewById(R.id.common_loading_layout);
        loadingImg = (ImageView) curMyView.findViewById(R.id.common_loading__img);
        banners = new ArrayList<>();
        mContentAdapter = new InfoAdapter();
        lv.setAdapter(mContentAdapter);

    }

    void initView() {
        tvTitle = (TextView) curMyView.findViewById(R.id.common_header_name);
        tvTitle.setText(R.string.maintab_enter);
        ivPersion = (ImageView) curMyView.findViewById(R.id.common_header_persion);
        ivPersion.setVisibility(View.VISIBLE);
        ivPersion.setOnClickListener(this);

        LinearLayout containerView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.region_content_layout, null);
        switchImg = (ImageView) containerView.findViewById(R.id.column_switch_img);
        switchView = containerView.findViewById(R.id.column_switch_layout);
        bgaBanner = (BGABanner) curMyView.findViewById(R.id.banner);
//        modelView = (RegionModelView) curMyView.findViewById(R.id.regionModelView);
        commonTitle = bActivity.getLayoutInflater().inflate(R.layout.common_title, null);
        empty = (RelativeLayout) curMyView.findViewById(R.id.empty);
        screenHeight = bActivity.getWindowManager().getDefaultDisplay().getHeight();
        ViewTreeObserver vto1 = commonTitle.getViewTreeObserver();
        vto1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                commonTitle.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                titleHight = commonTitle.getHeight();
                ViewTreeObserver vto2 = modelView.getViewTreeObserver();
                vto2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        modelView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        regionHight = modelView.getHeight();
                        ViewTreeObserver vto3 = bgaBanner.getViewTreeObserver();
                        vto3.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                            @Override
                            public void onGlobalLayout() {
                                bgaBanner.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                                bannerHight = bgaBanner.getHeight();
                                //51是底部导航栏的高度dp
                                int emptyHeight = screenHeight - titleHight - regionHight
                                        - bannerHight - getStatusBarHeight() - Util.dp2px(bActivity, 51);
                                ;
                                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                                        , emptyHeight);
                                empty.setLayoutParams(lp);
                            }
                        });
                    }
                });
            }
        });
    }

    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = bActivity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = bActivity.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    /**
     * 下拉刷新
     */
    private void refresh() {
        //TODO
        if (currentModelId != -1) {
            getModelData(currentModelId, 1);
        } else {
            refreshView.onRefreshComplete();
        }
    }

    /**
     * 加载更多
     */
    private void loadMore() {
        if (getDataSize() == 0) {
            PullToRefreshUtil.setLoadLabel(refreshView, "没有更多数据了");
        } else {
            if (getHasMore()) {
                //加载下一页
                getNextPage();
                return;
            } else if (isGotMaxSize()) {
                //已经达到了最大条数，
                PullToRefreshUtil.setLoadLabel(refreshView, "已经达到了最大条数");
            } else {
                //没有更多了， 所以不再加载下一页
                PullToRefreshUtil.setLoadLabel(refreshView, "没有更多数据了");
            }
        }
        refreshView.onRefreshComplete();
    }

    //为轮播图加载数据
    @Override
    public void fillBannerItem(BGABanner banner, ImageView itemView, BannerInfo model, int position) {
        Glide.with(bActivity)
                .load(model.getImgUrl()+"?w=640&h=260&c=0&p=0")
                .placeholder(R.drawable.bg_big_image)
                .error(R.drawable.bg_big_image)
                .dontAnimate()
                .centerCrop()
                .into(itemView);
    }

    @Override
    public void onBannerItemClick(BGABanner banner, ImageView itemView, BannerInfo info, int position) {
        switch (info.getType()) {
            case BannerInfo.TYPE_BANNER:

                break;
            case BannerInfo.TYPE_BOOKS:

                break;
            case BannerInfo.TYPE_BOOKSURL:
                bActivity.goBookDetailActivity(info.getBooks());
                break;
            case BannerInfo.TYPE_URL:
            case BannerInfo.TYPE_INFORMATION:
                bActivity.goWebViewActivity(info);
                break;
        }
    }

    @Override
    public void dispose() {
        isLastSuccess = false;
        if (null != banners) {
            banners.removeAll(banners);
        }
        super.dispose();
    }

    @Override
    public int enter(IUIPage<?> arg0) {
        showGuide();
        if (NetworkUtil.isNetAvailable(bActivity)) {
            if (!isLastSuccess) {
                updateLoadingView(0);
            }
            //请求banner轮播数据
            getViewPagerBanner();
            setRegionContentViewListener(new RegionContentViewListener() {
                @Override
                public void OnLoadDataCompleted(int flag) {
                    modelView.setCanSwitchModule(true);
                    if (flag == 1) { //首次装载
                        refreshView.onRefreshComplete();
                    } else if (flag == 2) {//装载更多
                        refreshView.onRefreshComplete();
                    }
                }
            });

            //增加模块视图
            if (modelView == null) {
                modelView = (RegionModelView) curMyView.findViewById(R.id.regionModelView);
                modelView.setOnModuleSelectedListener(this);
                modelView.setBaseActivity(bActivity);
                modelView.getModules();
            }
        } else {
            new NoNetDialog(bActivity).show();
        }
        return 0;
    }

    @Override
    public int leave(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public void notifyView(int arg0, Bundle arg1) {
        switch (arg0) {
            case DefaultConsts.PAGE_ONRESUME_CODE:
                if (currentModelId != -1) {
                    getModelData(currentModelId, 1);
                }
                break;
            case BaseBusinessActivity.COMMENTS_REQUEST_CODE:
                //contentItemView.getModelData(currentModelId, 1);
                updateTheCommentsCount();
                break;
        }
    }

    @Override
    public void setStatus(int arg0) {

    }

    @Override
    public View updateView(int arg0, ITaskResult arg1) {
        // TODO Auto-generated method stub
        return null;
    }

    /******************************
     * list 的 item click 方法
     *****************************************/

    private void getViewPagerBanner() {
        bgaBanner.setAdapter(this);
        bgaBanner.setDelegate(this);
        NewActionHelp.qryEnterpriseZoneBanner(bActivity, new ObjectHttpResponseHandler<List<BannerInfo>>() {
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                Log.e("111111fail", "qryEnterpriseZoneBanner" + s);
                bActivity.getUIHandler().post(new Runnable() {
                    @Override
                    public void run() {
                        updateLoadingView(-1);
                    }
                });
                isLastSuccess = false;
            }

            @Override
            public void onSuccess(int i, Header[] headers, List<BannerInfo> bannerInfos, String s) {
                Log.e("111111OK", "qryEnterpriseZoneBanner" + s);
                banners.clear();
                if (bannerInfos.size() <= 1) {
                    banners = bannerInfos;
                } else {
                    banners.addAll(bannerInfos);
                }

                bActivity.getUIHandler().post(new Runnable() {
                    @Override
                    public void run() {
                        updateLoadingView(1);
                        bgaBanner.setData(banners, null);
                    }
                });
            }

            @Override
            public Type getType() {
                return new TypeToken<List<BannerInfo>>() {
                }.getType();
            }
        });
    }

    /**
     * @param refreshFlag 1为 下拉刷新， 2为得到数据
     */
    public void getModelData(long mId, int refreshFlag) {
        moduleId = mId;
        lv.setFocusable(false);
        this.myRefreshFlag = refreshFlag;
        if (refreshFlag == 2) {
            mContentItemList.clear();
//            views.clear();
            mContentAdapter.notifyDataSetChanged();
//            setListViewHeightBasedOnChildren(lv);
            updateSwitchView(0);//显示动画
        }

        currentPage = 1;
        currentPublishTime = 0;
        //todo 调用真实的接口， 获取数据
        getContentItemDatas();
    }

    public void updateTheCommentsCount() {
        //获取评论数
        new QryCommentPraiseNumAction(bActivity, targetType, targetValue, new BookCommentsNumberActionListener()).start();
    }

    public int getTotalItemCount() {
        return mTotalItemCount;
    }

    public void getNextPage() {
        if (mTotalItemCount >= CONTENT_ITEM_MAX_SIZE) return;
        currentPage++;
        //getFakeContentItemDatas();
        getContentItemDatas();
    }

    public boolean isGotMaxSize() {
        return mTotalItemCount >= CONTENT_ITEM_MAX_SIZE;
    }

    public boolean getHasMore() {
        return hasMore;
    }

    public void setRegionContentViewListener(RegionContentViewListener contentViewListener) {
        this.contentViewListener = contentViewListener;
    }

    private void refreshUIData() {
        if (null == mContentItemList || mContentItemList.size() == 0) {
            empty.setVisibility(View.VISIBLE);
        } else {
            empty.setVisibility(View.GONE);
        }
        mTotalItemCount = mContentItemList.size();
        if (currentPage == 1) {//刷新
            mContentAdapter.notifyDataSetChanged();
//            setListViewHeightBasedOnChildren(lv);
            if (myRefreshFlag == 2) {
                updateSwitchView(1);//隐藏动画
            }
            if (contentViewListener != null) {
                contentViewListener.OnLoadDataCompleted(1);
            }
        } else {//取下一页
            if (contentViewListener != null) {
                contentViewListener.OnLoadDataCompleted(2);//装载更多
            }
            mContentAdapter.notifyDataSetChanged();
        }
    }

    /**
     * 跳转到图文详情页
     *
     * @param url
     */
    private void gotoImageTextActivity(String url, String title, String contentDetailId) {
        Intent intent = new Intent(bActivity, ImageTextActivity.class);
        intent.putExtra(DefaultConsts.req_url_s, url);
        intent.putExtra(DefaultConsts.title_s, title);
        intent.putExtra(DefaultConsts.COMMENT_TARGET_TYPE, "2");
        intent.putExtra(DefaultConsts.COMMENT_TARGET_VALUE, contentDetailId);
        bActivity.startActivity(intent);
    }

    /**
     * 视频资讯的详情页
     */
    private void gotoVideoDetailActivity(RegionContentItemBean contentItemBean) {
        Intent intent = new Intent(bActivity, VideoDetailActivity.class);
        intent.putExtra("video", contentItemBean);
        bActivity.startActivity(intent);
    }

    /**
     * 跳转到查看图集的页面
     *
     * @param position 1 为直接进入查看, 2 为可能要进入到瀑布流页面
     */
    private void gotoImageViewerActivity(int position/*, int type*/) {
        int imgCounts = 0;
        RegionContentItemBean contentItem = mContentItemList.get(position);
        ImageCollection imageSet = contentItem.getImageSet();
        imgCounts = imageSet.getImageCollectionNum();
        Intent intent;
        if (imgCounts == 0) {
            Toast.makeText(bActivity, "图集已下架", Toast.LENGTH_SHORT).show();
            return;
        }
        if (/*type == 1 || ( type == 2 && */imgCounts <= IMAGE_COUNT/*) */) {
            //直接进入看图片
            intent = new Intent(bActivity, AtlasSeeActivity.class);
            intent.putExtra(AtlasSeeActivity.FROM_TYPE, DefaultConsts.TAG_FROM_ENTERPRISE);
            intent.putExtra(AtlasSeeActivity.IMAGE_COUNT, imgCounts);
        } else {//进入到瀑布流页面
            intent = new Intent(bActivity, AtlasActivity.class);
            intent.putExtra(AtlasActivity.ATLAS_NAME, imageSet.getTitle());
        }
        //todo  设置图集的数据
        intent.putExtra(AtlasActivity.ATLAS_ID, imageSet.getImageCollectionId());
        bActivity.startActivity(intent);
    }

    @Override
    public void onItemClick(Object item, View view, int position) {

        RegionContentItemBean contentItem = mContentItemList.get(position);
        //
        String contentType = contentItem.getType();
        if (contentType.equalsIgnoreCase("1")) { //单条资讯
            //todo 跳转到图文详情
            SingleNews singleNews = contentItem.getSingleNews();
            gotoImageTextActivity(singleNews.getHtmlUrl(), singleNews.getTitle(), singleNews.getModelContentDetailId() + "");
        } else if (contentType.equalsIgnoreCase("2")) {//多条资讯
            //每个已经处理了， 这里不需要处理
        } else if (contentType.equalsIgnoreCase("3")) {//音频

        } else if (contentType.equalsIgnoreCase("4")) {//视频
            gotoVideoDetailActivity(contentItem);
        } else if (contentType.equalsIgnoreCase("5")) { //图集
            //todo 跳转到查看图集图片
            gotoImageViewerActivity(position/*,2*/);
        } else if (contentType.equalsIgnoreCase("6")) { //单本书籍
            //跳转到书籍详情
            SingleBook singleBook = contentItem.getSingleBook();
            BookInfo bookInfo = singleBook.getBookInfo();
            if (bookInfo == null) return;
            //#ifdef SHOW_OLDBOOKDETAIL
            //$ Intent intent = new Intent(bActivity, BookDetailActivity.class);
            //#else
            Intent intent = new Intent(bActivity, NewBookDetailActivity.class);
            //#endif
            bookInfo.setAuthor("");
            intent.putExtra("BookInfo", bookInfo);
            bActivity.startActivity(intent);
        }
    }

    private void setMultiNewsContent(int position1, int position2, MultiinfoViewHolder multiInfo) {
        RegionContentItemBean contentItem = mContentItemList.get(position1);
        MultiNews multiNews = contentItem.getMutilNews();
        TextView tv_title = null, tv_splitor = null;
        ImageView im_image = null;
        View frame = null;

        if (position2 == 0) {
            frame = multiInfo.fl_biginfo;
            tv_title = multiInfo.tv_biginfo_title;
            im_image = multiInfo.im_bigimage;
        }

        if (position2 == 1) {
            tv_splitor = multiInfo.tv_splitor1;
            frame = multiInfo.rl_smallinfo1;
            tv_title = multiInfo.tv_smallinfo1;
            im_image = multiInfo.im_smallimage1;
        }
        if (position2 == 2) {
            tv_splitor = multiInfo.tv_splitor2;
            frame = multiInfo.rl_smallinfo2;
            tv_title = multiInfo.tv_smallinfo2;
            im_image = multiInfo.im_smallimage2;
        }
        if (position2 == 3) {
            tv_splitor = multiInfo.tv_splitor3;
            frame = multiInfo.rl_smallinfo3;
            tv_title = multiInfo.tv_smallinfo3;
            im_image = multiInfo.im_smallimage3;
        }

        int defaultImgRes;
        if (position2 != 0) {
            tv_splitor.setVisibility(View.VISIBLE);
            defaultImgRes = R.drawable.bg_small_image;

        } else {
            defaultImgRes = R.drawable.bg_big_image;
        }

        frame.setVisibility(View.VISIBLE);
        frame.setOnClickListener(multiIfoOnclickListener);
        String tagSring = "" + position1 + REGION_SPLITOR + position2;
        frame.setTag(tagSring);
        //根据不同的类型，可能填充不同的内容
        String DesStr = "";
        String contentType = multiNews.getNewsType(position2);
        if (contentType.equalsIgnoreCase("1")) { //单条资讯
            SingleNews singleNews = (SingleNews) multiNews.getNewsObject(position2);
            DesStr = singleNews.getTitle();
            tv_title.setText(DesStr);
//			im_image.setImageUrl(singleNews.getCoverImageUrl(), defaultImgRes);
            GlideUtil.load(bActivity, singleNews.getCoverImageUrl(), defaultImgRes, im_image);
        } else if (contentType.equalsIgnoreCase("3")) {//音频
            AudioAndVideo audioNews = (AudioAndVideo) multiNews.getNewsObject(position2);
            DesStr = audioNews.getTitle();
            tv_title.setText(DesStr);
//			im_image.setImageUrl(audioNews.getCoverImageUrl(), defaultImgRes);
            GlideUtil.load(bActivity, audioNews.getCoverImageUrl(), defaultImgRes, im_image);
        } else if (contentType.equalsIgnoreCase("4")) {//视频
            AudioAndVideo videoNews = (AudioAndVideo) multiNews.getNewsObject(position2);
            DesStr = videoNews.getTitle();
            tv_title.setText(DesStr);
//			im_image.setImageUrl(videoNews.getCoverImageUrl(), defaultImgRes);
            GlideUtil.load(bActivity, videoNews.getCoverImageUrl(), defaultImgRes, im_image);
        } else if (contentType.equalsIgnoreCase("5")) { //图集
            ImageCollection imgsSet = (ImageCollection) multiNews.getNewsObject(position2);
            DesStr = imgsSet.getTitle();
            tv_title.setText(DesStr);
//			im_image.setImageUrl(imgsSet.getCoverImageUrl(), defaultImgRes);
            GlideUtil.load(bActivity, imgsSet.getCoverImageUrl(), defaultImgRes, im_image);
        } else if (contentType.equalsIgnoreCase("6")) { //单本书籍
            SingleBook singleBook = (SingleBook) multiNews.getNewsObject(position2);
            DesStr = singleBook.getTitle();
            tv_title.setText(DesStr);
            BookInfo bookInfo = singleBook.getBookInfo();
            String url = "";
            if (bookInfo != null) {
                url = bookInfo.getLogoUrl();
            }
            if (Util.isEmpty(url)) {
                url = singleBook.getCoverImageUrl();
            }
//			im_image.setImageUrl(url, defaultImgRes);
            GlideUtil.load(bActivity, url, defaultImgRes, im_image);
        }
    }

    /******************************
     * 一些私有的方法
     *****************************************/

    private void getContentItemDatas() {
        //加载企业动态列表
        NewActionHelp.qryModuleContentList(bActivity, moduleId, currentPublishTime, PAGESIZE, new ObjectHttpResponseHandler<Map<String, List<RegionContentItemBean>>>() {
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                Log.e("111111Fail", "qryModuleContentList" + s);
                bActivity.getUIHandler().post(new Runnable() {
                    @Override
                    public void run() {
                        if (contentViewListener != null) {
                            contentViewListener.OnLoadDataCompleted(2);//装载更多
                        }
                        updateSwitchView(-1);//加载失败
                    }
                });
            }

            @Override
            public void onSuccess(int i, Header[] headers, Map<String, List<RegionContentItemBean>> stringListMap, String s) {
                Log.e("111111OK", "qryModuleContentList" + s);
                List<RegionContentItemBean> contentItems = stringListMap.get("modelContentList");
                removeAudioAndVideo(contentItems);//临时移除音频的数据、去除为空的数据
                if (contentItems == null || contentItems.size() == 0) {
                    //取到的内空为空
                    hasMore = false;
                    bActivity.getUIHandler().post(new Runnable() {
                        @Override
                        public void run() {
                            if (contentViewListener != null) {
                                contentViewListener.OnLoadDataCompleted(2);//装载更多
                            }
                            if (currentPage == 1) {//只有当前是重新刷新时， 才更新ui为无内容
                                updateSwitchView(2);//内容为空
                            }
                        }
                    });
                    return;
                }
                hasMore = contentItems.size() >= PAGESIZE;
                if (currentPage == 1) {//刷新
                    mContentItemList = contentItems;
                } else {//取下一页
                    mContentItemList.addAll(contentItems);
                }
                RegionContentItemBean lastItem = mContentItemList.get(mContentItemList.size() - 1);
                currentPublishTime = lastItem.getPublishTime();
                //刷新UI
                bActivity.getUIHandler().post(new Runnable() {
                    @Override
                    public void run() {
                        refreshUIData();
                    }
                });
            }

            @Override
            public Type getType() {
                return new TypeToken<Map<String, List<RegionContentItemBean>>>() {
                }.getType();
            }
        });
    }

    /**
     * 栏目切换加载动画
     *
     * @param flag 0:加载中，1：加载完成，2: 内容为空  -1：加载失败
     */
    private void updateSwitchView(int flag) {
        switch (flag) {
            case -1:
                switchView.setVisibility(View.VISIBLE);
                lv.setVisibility(View.GONE);
                if (switchDrawable != null && switchDrawable.isRunning()) {
                    switchDrawable.stop();
                }
                //TODO
                switchImg.setBackgroundResource(R.drawable.home_loading_fail);
                break;
            case 0:
                switchView.setVisibility(View.VISIBLE);
                lv.setVisibility(View.GONE);
                switchImg.setBackgroundResource(R.drawable.home_progress);
//				switchImg.setBackgroundResource(R.anim.column_switch_anim);
                switchDrawable = (AnimationDrawable) switchImg.getBackground();
                switchDrawable.start();
                break;
            case 1:
                switchView.setVisibility(View.GONE);
                lv.setVisibility(View.VISIBLE);
                break;
            case 2:
                switchView.setVisibility(View.GONE);
                lv.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 过滤掉音频文件和为空的文件
     *
     * @param contentItems
     */
    private void removeAudioAndVideo(List<RegionContentItemBean> contentItems) {
        if (contentItems == null || contentItems.size() == 0) return;
        for (int i = 0; i < contentItems.size(); i++) {
            RegionContentItemBean contentItem = contentItems.get(i);
            String type = contentItem.getType();
            String bean = contentItem.getDataJson();
            if (null == type || type.equalsIgnoreCase("3") || null == bean || bean.length() == 0) {
                contentItems.remove(contentItem);
            }
            if (type.equalsIgnoreCase("4")) {
                list.add(contentItem.getModuleContentId() + " " + contentItem.getVideoNews().getHtmlUrl());
            }
        }
    }

    public int getDataSize() {
        return (mContentItemList == null || mContentItemList.isEmpty()) ? 0 : mContentItemList.size();
    }

    private void initGuide() {
        util = QyreaderPerferencesUtil.getInstance(bActivity, DefaultConsts.FIRST_TAG);
        dialog = new GuideDialog(bActivity, R.layout.enterprise_page_firstin);
    }

    private void showGuide() {
        showHelp = util.getShowEnterpriseHelp();
        if (showHelp) {
            if (null != dialog && !dialog.isShowing()) {
                dialog.show();
            }
            util.setShowEnterpriseHelp(false);
        }
    }

    /**
     * 首次进入page加载动画
     *
     * @param flag 0:加载中，1：加载完成，-1：加载失败
     */
    private void updateLoadingView(int flag) {
        switch (flag) {
            case -1:
                loadingView.setVisibility(View.VISIBLE);
                refreshView.setVisibility(View.GONE);
                if (animationDrawable != null && animationDrawable.isRunning()) {
                    animationDrawable.stop();
                }
                loadingImg.setBackgroundResource(R.drawable.home_loading_fail);
                break;
            case 0:
                loadingView.setVisibility(View.VISIBLE);
                refreshView.setVisibility(View.GONE);
                loadingImg.setBackgroundResource(R.drawable.home_progress);
                animationDrawable = (AnimationDrawable) loadingImg.getBackground();
                animationDrawable.start();
                break;
            case 1:
                loadingView.setVisibility(View.GONE);
                refreshView.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.common_header_persion:
                bActivity.goPersonalActivity();
                break;
//            case R.id.new_enterprise_goto_top:
//                gotoTop();
//                break;
            case R.id.common_title_layout:
                titleDoubleClick();
                break;
        }
    }

    /**
     * 回到顶部
     */
    private void gotoTop() {
        lv.post(new Runnable() {
            @Override
            public void run() {
                refreshView.getRefreshableView().scrollTo(0, 0);
            }
        });
    }

    /**
     * 标题栏双击，回到顶部
     */
    private void titleDoubleClick() {
        if (clickCount == 0) {
            preClickTime = System.currentTimeMillis();
            clickCount++;
        } else if (clickCount == 1) {
            if ((System.currentTimeMillis() - preClickTime) < defalultValue) {
                gotoTop();
            }
            clickCount = 0;
            preClickTime = 0;
        } else {
            clickCount = 0;
            preClickTime = 0;
        }
    }

    @Override
    public void moduleSelected(long modelId) {
        currentModelId = modelId;
        PullToRefreshUtil.initLabel(context, refreshView);
        getModelData(modelId, 2);
    }

    /**
     * 读取模块数据时的错误处理
     */
    @Override
    public void onError(String error) {

    }

    public interface RegionContentViewListener {
        /**
         * @param flag 1为首次装载， 2 为装载更多
         */
        void OnLoadDataCompleted(int flag);
    }

    private static class SingleinfoViewHolder {
        TextView tv_publishtime, tv_info_title, tv_info_from, tv_item_introduce;
        ImageView im_bigimage, im_leftimage, im_rightimage;
        TextView tv_comments_count;
        ImageView im_comments;
    }

    private static class MultiinfoViewHolder {
        TextView tv_publishtime, tv_biginfo_title, tv_smallinfo1, tv_smallinfo2, tv_smallinfo3;
        TextView tv_splitor1, tv_splitor2, tv_splitor3;
        ImageView im_bigimage, im_smallimage1, im_smallimage2, im_smallimage3;
        View fl_biginfo;
        View rl_smallinfo1, rl_smallinfo2, rl_smallinfo3;
    }

    private static class SingleBookViewHolder {
        TextView tv_publishtime, tv_book_title, tv_book_name, tv_book_author, tv_book_lookedcount, tv_book_introduce;
        BookCoverView im_book_cover;
        TextView tv_comments_count;
        ImageView im_comments;
    }

    private static class imagesetViewHolder {
        TextView tv_publishtime, tv_imageset_title, tv_imageset_introduce;
        ImageView im_imageset_image3, im_imageset_image2, im_imageset_image1;
        FrameLayout fl_imageset;
        TextView tv_comments_count;
        ImageView im_comments;
    }

    private static class Mp4Holder {
        JCVideoPlayerStandard player_list_video;
        TextView tv_video_desc;
        TextView tv_video_title;
        ImageView im_comments;
        TextView tv_publishtime;
        TextView tv_comments_count;
    }

    private class InfoAdapter extends BaseAdapter {

        @Override
        public int getViewTypeCount() {
            return 6;
        }

        @Override
        public int getItemViewType(int position) {
            if (null != mContentItemList && position < mContentItemList.size()) {
                return Integer.parseInt(mContentItemList.get(position).getType());
            }
            return super.getItemViewType(position);
        }

        @Override
        public int getCount() {
            return mContentItemList.size();
        }

        @Override
        public Object getItem(int position) {
            return mContentItemList == null ? null : mContentItemList.get(position);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int position, View view, ViewGroup viewGroup) {
            if (view != null && view.getTag() != null && view.getTag() instanceof Mp4Holder) {
                ((Mp4Holder) view.getTag()).player_list_video.release();
            }
            final RegionContentItemBean contentItem = mContentItemList.get(position);
            LayoutInflater inflater = LayoutInflater.from(bActivity);
            SingleinfoViewHolder singleInfo = null;
            MultiinfoViewHolder multiInfo = null;
            Mp4Holder mp4Holder = null;
            imagesetViewHolder imageset = null;
            SingleBookViewHolder singlebook = null;
            int contentType = Integer.parseInt(contentItem.getType());
//            if (contentType==4){
//                contentItem.getVideoNews().setHtmlUrl("http://ic.snssdk.com/neihan/video/playback/?video_id=72e2402254ff486797b135146f800f4b&quality=480p&line=0&is_gif=0.mp4");
//            }
            switch (contentType) {
                case SINGLE_NEWS_TYPE:
                    if (view == null) {
                        singleInfo = new SingleinfoViewHolder();
                        view = inflater.inflate(R.layout.region_singleinfo_item, null);
                        singleInfo.tv_info_title = (TextView) view.findViewById(R.id.tv_info_title);
                        singleInfo.tv_info_from = (TextView) view.findViewById(R.id.tv_info_from);
                        singleInfo.tv_item_introduce = (TextView) view.findViewById(R.id.tv_item_introduce);
                        singleInfo.im_bigimage = (ImageView) view.findViewById(R.id.im_bigimage);
                        singleInfo.im_leftimage = (ImageView) view.findViewById(R.id.im_leftimage);
                        singleInfo.im_rightimage = (ImageView) view.findViewById(R.id.im_rightimage);
                        singleInfo.tv_publishtime = (TextView) view.findViewById(R.id.tv_publishtime);
                        singleInfo.tv_comments_count = (TextView) view.findViewById(R.id.tv_comments_count);
                        singleInfo.im_comments = (ImageView) view.findViewById(R.id.im_comments);
                        view.setTag(singleInfo);
                    } else {
                        singleInfo = (SingleinfoViewHolder) view.getTag();
                    }
                    SingleNews singleNews = contentItem.getSingleNews();
                    singleInfo.tv_info_title.setText(singleNews.getTitle());
                    String fromSource = singleNews.getFromSource();
                    if (Util.isEmpty(fromSource)) {
                        singleInfo.tv_info_from.setVisibility(View.GONE);
                    } else {
                        singleInfo.tv_info_from.setText("来源：" + fromSource);
                    }
                    if (Util.isEmpty(singleNews.getShortDesc())) {
                        singleInfo.tv_item_introduce.setVisibility(View.GONE);
                    } else {
                        singleInfo.tv_item_introduce.setText(singleNews.getShortDesc());
                    }
                    int layoutType = singleNews.getLayoutType();
                    if (layoutType == 1) {//无图
                        singleInfo.im_bigimage.setVisibility(View.GONE);
                        singleInfo.im_leftimage.setVisibility(View.GONE);
                        singleInfo.im_rightimage.setVisibility(View.GONE);
                    } else if (layoutType == 2) {//大图
                        GlideUtil.load(bActivity, singleNews.getCoverImageUrl(), R.drawable.bg_big_image, singleInfo.im_bigimage);
                        singleInfo.im_leftimage.setVisibility(View.GONE);
                        singleInfo.im_rightimage.setVisibility(View.GONE);
                    } else if (layoutType == 3) {//小左图
                        singleInfo.im_bigimage.setVisibility(View.GONE);
                        GlideUtil.load(bActivity, singleNews.getCoverImageUrl(), R.drawable.bg_small_image, singleInfo.im_leftimage);
                        singleInfo.im_rightimage.setVisibility(View.GONE);
                    } else if (layoutType == 4) {//小右图
                        singleInfo.im_bigimage.setVisibility(View.GONE);
                        singleInfo.im_leftimage.setVisibility(View.GONE);
                        GlideUtil.load(bActivity, singleNews.getCoverImageUrl(), R.drawable.bg_big_image, singleInfo.im_rightimage);

                    }
                    singleInfo.tv_publishtime.setText(DateUtil.getRegionTime(contentItem.getPublishTime()));
                    singleInfo.tv_comments_count.setText(singleNews.getCommentNum() + "");
                    singleInfo.im_comments.setTag("2" + REGION_SPLITOR + singleNews.getModelContentDetailId());//专区内容的资讯
                    singleInfo.im_comments.setOnClickListener(commentsOnclickListener);
//                    view.setTag(singleNews.getHtmlUrl());
                    break;
                case MULTI_NEWS_TYPE:
                    if (view == null) {
                        view = inflater.inflate(R.layout.region_multiinfo_item, null);
                        multiInfo = new MultiinfoViewHolder();
                        multiInfo.tv_biginfo_title = (TextView) view.findViewById(R.id.tv_biginfo_title);
                        multiInfo.tv_smallinfo1 = (TextView) view.findViewById(R.id.tv_smallinfo1);
                        multiInfo.tv_smallinfo2 = (TextView) view.findViewById(R.id.tv_smallinfo2);
                        multiInfo.tv_smallinfo3 = (TextView) view.findViewById(R.id.tv_smallinfo3);

                        multiInfo.tv_splitor1 = (TextView) view.findViewById(R.id.tv_splitor1);
                        multiInfo.tv_splitor2 = (TextView) view.findViewById(R.id.tv_splitor2);
                        multiInfo.tv_splitor3 = (TextView) view.findViewById(R.id.tv_splitor3);

                        multiInfo.im_bigimage = (ImageView) view.findViewById(R.id.im_bigimage);
                        multiInfo.im_smallimage1 = (ImageView) view.findViewById(R.id.im_smallimage1);
                        multiInfo.im_smallimage2 = (ImageView) view.findViewById(R.id.im_smallimage2);
                        multiInfo.im_smallimage3 = (ImageView) view.findViewById(R.id.im_smallimage3);

                        multiInfo.fl_biginfo = view.findViewById(R.id.fl_biginfo);
                        multiInfo.rl_smallinfo1 = view.findViewById(R.id.rl_smallinfo1);
                        multiInfo.rl_smallinfo2 = view.findViewById(R.id.rl_smallinfo2);
                        multiInfo.rl_smallinfo3 = view.findViewById(R.id.rl_smallinfo3);

                        multiInfo.tv_publishtime = (TextView) view.findViewById(R.id.tv_publishtime);
                        view.setTag(multiInfo);
                    } else {
                        multiInfo = (MultiinfoViewHolder) view.getTag();
                    }
                    MultiNews multiNews = contentItem.getMutilNews();
                    int count = multiNews.getNewsCount();
                    for (int i = 0; i < count; i++) {
                        setMultiNewsContent(position, i, multiInfo);
                    }
                    multiInfo.tv_publishtime.setText(DateUtil.getRegionTime(contentItem.getPublishTime()));
                    break;
                case AUDIO_NEWS_TYPE:

                    break;
                case VIDEO_NEWS_TYPE:
                    JCVideoPlayer.clearSavedProgress(bActivity, null);
                    if (view != null && view.getTag() != null && view.getTag() instanceof Mp4Holder) {
                        mp4Holder = (Mp4Holder) view.getTag();
                    } else {
                        view = inflater.inflate(R.layout.item_lv_video, null);
                        mp4Holder = new Mp4Holder();
                        mp4Holder.player_list_video = (JCVideoPlayerStandard) view.findViewById(R.id.player_list_video);
                        mp4Holder.tv_video_desc = (TextView) view.findViewById(R.id.tv_video_desc);
                        mp4Holder.tv_video_title = (TextView) view.findViewById(R.id.tv_video_title);
                        mp4Holder.tv_publishtime = (TextView) view.findViewById(R.id.tv_publishtime);
                        mp4Holder.tv_comments_count = (TextView) view.findViewById(R.id.tv_comments_count);
                        mp4Holder.im_comments = (ImageView) view.findViewById(R.id.im_comments);
                        mp4Holder.player_list_video.tinyBackImageView.setVisibility(View.GONE);
                        mp4Holder.player_list_video.backButton.setVisibility(View.GONE);
                        mp4Holder.player_list_video.titleTextView.setVisibility(View.GONE);
                        view.setTag(mp4Holder);
                    }
                    AudioAndVideo audioAndVideo = contentItem.getVideoNews();
                    if (null == audioAndVideo.getTitle()) {
                        audioAndVideo.setTitle("");
                    }
                    mp4Holder.player_list_video.setUp(
                            audioAndVideo.getHtmlUrl(),
                            JCVideoPlayer.SCREEN_LAYOUT_LIST,
                            audioAndVideo.getTitle(), false);
                    Glide.with(bActivity)
                            .load(audioAndVideo.getCoverImageUrl())
                            .placeholder(R.drawable.bg_big_image)
                            .error(R.drawable.bg_big_image)
                            .into(mp4Holder.player_list_video.thumbImageView);
                    mp4Holder.player_list_video.thumbImageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    if (Util.isEmpty(audioAndVideo.getTitle())) {
                        mp4Holder.tv_video_title.setText("");
                    } else {
                        mp4Holder.tv_video_title.setText(audioAndVideo.getTitle());
                    }
                    if (Util.isEmpty(audioAndVideo.getShortDesc())) {
                        mp4Holder.tv_video_desc.setText("");
                    } else {
                        mp4Holder.tv_video_desc.setText(audioAndVideo.getShortDesc());
                    }
                    mp4Holder.tv_publishtime.setText(DateUtil.getRegionTime(contentItem.getPublishTime()));
                    mp4Holder.tv_comments_count.setText(audioAndVideo.getCommentNum() + "");
                    mp4Holder.player_list_video.thumbImageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            gotoVideoDetailActivity(contentItem);
                        }
                    });
                    mp4Holder.im_comments.setTag("2" + REGION_SPLITOR + audioAndVideo.getModelContentDetailId());//视频
                    mp4Holder.im_comments.setOnClickListener(commentsOnclickListener);
                    break;
                case IMAGE_SET_TYPE:
                    if (view == null) {
                        view = inflater.inflate(R.layout.region_imageset_item, null);
                        imageset = new imagesetViewHolder();
                        imageset.tv_imageset_title = (TextView) view.findViewById(R.id.tv_imageset_title);
                        imageset.tv_imageset_introduce = (TextView) view.findViewById(R.id.tv_imageset_introduce);

                        imageset.im_imageset_image3 = (ImageView) view.findViewById(R.id.im_imageset_image3);
                        imageset.im_imageset_image2 = (ImageView) view.findViewById(R.id.im_imageset_image2);
                        imageset.im_imageset_image1 = (ImageView) view.findViewById(R.id.im_imageset_image1);

                        imageset.tv_publishtime = (TextView) view.findViewById(R.id.tv_publishtime);
                        imageset.tv_comments_count = (TextView) view.findViewById(R.id.tv_comments_count);
                        imageset.im_comments = (ImageView) view.findViewById(R.id.im_comments);

                        imageset.fl_imageset = (FrameLayout) view.findViewById(R.id.fl_imageset);
                        imageset.fl_imageset.setTag(position);
                        view.setTag(imageset);
                    } else {
                        imageset = (imagesetViewHolder) view.getTag();
                    }
                    imageset.fl_imageset.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Object objUrl = v.getTag();
                            if (objUrl == null) return;
                            int pos = (Integer) objUrl;
                            //todo 直接跳转到查看图片集
                            gotoImageViewerActivity(pos/*,2*/);
                        }
                    });
                    ImageCollection imageSet = contentItem.getImageSet();
                    imageset.tv_imageset_title.setText(imageSet.getTitle());
                    imageset.tv_imageset_introduce.setText(imageSet.getShortDesc());
                    GlideUtil.load(bActivity, imageSet.getCoverImageUrl(), R.drawable.bg_big_image, imageset.im_imageset_image1);
                    imageset.tv_publishtime.setText(DateUtil.getRegionTime(contentItem.getPublishTime()));
                    imageset.tv_comments_count.setText(imageSet.getCommentNum() + "");
                    imageset.im_comments.setTag("4" + REGION_SPLITOR + imageSet.getImageCollectionId());//图集
                    imageset.im_comments.setOnClickListener(commentsOnclickListener);
                    break;
                case SINGLE_BOOK_TYPE:
                    if (view == null) {
                        view = inflater.inflate(R.layout.region_singlebook_item, null);
                        singlebook = new SingleBookViewHolder();
                        singlebook.tv_book_title = (TextView) view.findViewById(R.id.tv_book_title);
                        singlebook.tv_book_name = (TextView) view.findViewById(R.id.tv_book_name);
                        singlebook.tv_book_author = (TextView) view.findViewById(R.id.tv_book_author);
                        singlebook.tv_book_lookedcount = (TextView) view.findViewById(R.id.tv_book_lookedcount);
                        singlebook.tv_book_introduce = (TextView) view.findViewById(R.id.tv_book_introduce);
                        singlebook.im_book_cover = (BookCoverView) view.findViewById(R.id.im_book_cover);
                        singlebook.tv_publishtime = (TextView) view.findViewById(R.id.tv_publishtime);
                        singlebook.tv_comments_count = (TextView) view.findViewById(R.id.tv_comments_count);
                        singlebook.im_comments = (ImageView) view.findViewById(R.id.im_comments);
                        view.setTag(singlebook);
                    } else {
                        singlebook = (SingleBookViewHolder) view.getTag();
                    }
                    SingleBook singleBook = contentItem.getSingleBook();
                    singlebook.tv_book_title.setText(singleBook.getTitle());
                    BookInfo bookInfo = singleBook.getBookInfo();
                    if (bookInfo != null) {
                        singlebook.tv_book_name.setText(bookInfo.getName());
                        singlebook.tv_book_author.setText("作者: " + bookInfo.getAuthor());
                        String introduce = singleBook.getShortDesc();
                        if (Util.isEmpty(introduce)) {
                            introduce = bookInfo.getEditorRecommend();
                            if (Util.isEmpty(introduce)) {
                                introduce = bookInfo.getShortIntro();
                            }
                        }
                        singlebook.tv_book_introduce.setText(introduce);
                        singlebook.im_book_cover.setImageUrl(bookInfo.getLogoUrl(), bookInfo.getCoverTagPicUrl());
                        singlebook.tv_publishtime.setText(DateUtil.getRegionTime(contentItem.getPublishTime()));
                        singlebook.tv_comments_count.setText(singleBook.getCommentNum() + "");
                        singlebook.im_comments.setTag("1" + REGION_SPLITOR + bookInfo.getBookId());//书籍
                        singlebook.im_comments.setOnClickListener(commentsOnclickListener);
                    }
                    break;
            }
            return view;
        }
    }

    /**
     * 获取内容项评论数的 action listener
     */
    private class BookCommentsNumberActionListener
            extends
            BaseAction {
        @SuppressWarnings("unchecked")
        @Override
        public void OK(Object obj) {
            NumberInfo numbers = (NumberInfo) obj;
            final int commentsCount = numbers.commentNum;
            //更新UI上的评论数
            bActivity.getUIHandler().post(new Runnable() {
                @Override
                public void run() {
                    //更新UI
                    tv_comments_count.setText(commentsCount + "");
                }
            });
        }

        @Override
        public void onError() {
            super.onError();
            //通知 外部的调用者， 出错了。
            bActivity.getUIHandler().post(new Runnable() {
                @Override
                public void run() {
                    //todo 处理UI的不同显示
                    Util.showToast(bActivity, "获取评论数失败");
                }
            });
        }
    }
}
